from django.http import JsonResponse
from extends import douyin


def getPull(request):
    res_data = {
        'code': 0,
        'msg': 'success',
        'data': {}
    }

    if request.GET.get('url') is None:
        res_data['data'] = -1001
        res_data['msg'] = 'url is null'
        return JsonResponse(res_data)

    url = request.GET.get('url');
    res_url = douyin.get_real_url(url)

    if type(res_url) is dict:
        res_data['data'] = res_url
    else:
        res_data['code'] = -1
        res_data['msg'] = str(res_url)

    return JsonResponse(res_data)
